namespace OpenComposite.EII.Repository
{
	using System;
	using System.Collections.Generic;
	using System.Drawing;

	using OpenComposite.Base.Collections;
	using OpenComposite.Repository.Properties;

	[RepositoryItem(ItemType.Capability, "capabilities", "capability_id")]
	public class Capability : RepositoryItemBaseEx
	{
		#region Initialization

		/// <summary>
		/// Initializes a new instance of the <see cref="Capability"/> class.
		/// </summary>
		/// <param name="serviceProvider">The service provider.</param>
		/// <param name="bCreateNew">if set to <c>true</c> [b create new].</param>
		public Capability(IServiceProvider serviceProvider, bool bCreateNew)
			: base("capability_id", "capability_nm", "capability_desc", "capability_ntext", Resources.sNewCapability)
		{
			if ( bCreateNew )
				this.CreateNew();

			InitializeServiceProvider(serviceProvider);
		}

		#endregion Initialization

		#region Public Members

		#region Properties

		/// <summary>
		/// Gets a value indicating whether [allow drop].
		/// </summary>
		/// <value><c>true</c> if [allow drop]; otherwise, <c>false</c>.</value>
		public override bool AllowDrop
		{
			get
			{
				return true;
			}
		}

		/// <summary>
		/// Gets the allowed child types.
		/// </summary>
		/// <value>The allowed child types.</value>
		public override List<ItemType> AllowedChildTypes
		{
			get { return _LISTALLOWED; }
		}

		/// <summary>
		/// Gets the image.
		/// </summary>
		/// <value>The image.</value>
		public override System.Drawing.Image Image
		{
			get { return Resources.png_capability; }
		}

		/// <summary>
		/// Gets the image key.
		/// </summary>
		/// <value>The image key.</value>
		public override string ImageKey
		{
			get { return "capability"; }
		}

		/// <summary>
		/// Gets the type of the repository item.
		/// </summary>
		/// <value>The type of the repository item.</value>
		public override ItemType RepositoryItemType
		{
			get { return ItemType.Capability; }
		}

		/// <summary>
		/// Gets the repository item type description.
		/// </summary>
		/// <value>The repository item type description.</value>
		public override string RepositoryItemTypeDescription
		{
			get { return ""; }
		}

		/// <summary>
		/// Gets the name of the repository item type.
		/// </summary>
		/// <value>The name of the repository item type.</value>
		public override string RepositoryItemTypeName
		{
			get { return ItemTypes.GetDisplay(ItemType.Capability); }
		}

		/// <summary>
		/// Gets the selected image.
		/// </summary>
		/// <value>The selected image.</value>
		public override System.Drawing.Image SelectedImage
		{
			get { return this.Image; }
		}

		/// <summary>
		/// Gets the selected image key.
		/// </summary>
		/// <value>The selected image key.</value>
		public override string SelectedImageKey
		{
			get { return this.ImageKey; }
		}

		/// <summary>
		/// Gets the name of the table.
		/// </summary>
		/// <value>The name of the table.</value>
		public override string TableName
		{
			get { return "capabilities"; }
		}

		#endregion Properties

		#region Methods

		/// <summary>
		/// Copies this instance.
		/// </summary>
		/// <param name="deep"><c>true</c> to recursively copy the item and all subitems;
		/// <c>false</c> to copy only the item itself.</param>
		/// <returns>The copied item.</returns>
		public override IRepositoryItem Copy(bool deep)
		{
			Capability copy = new Capability(this, true);
			this.CopyDataRowToTarget(copy);
			return copy;
		}

		/// <summary>
		/// Gets the icon.
		/// </summary>
		/// <returns></returns>
		public override System.Drawing.Icon GetIcon()
		{
			Bitmap bmp = (Bitmap)this.Image;
			return Icon.FromHandle(bmp.GetHicon());
		}

		/// <summary>
		/// Gets the verbs.
		/// </summary>
		/// <returns></returns>
		public BindingListEx<Verb> GetVerbs()
		{
			return Global.Data.GetRepositoryHierarchyChildRepositoryList<Verb>(this);
		}

		#endregion Methods

		#endregion Public Members

		#region Private Members

		#region Constant/Read-Only Fields

		private static readonly List<ItemType> _LISTALLOWED =
			new List<ItemType>(new ItemType[] { ItemType.Verb });

		#endregion Constant/Read-Only Fields

		#endregion Private Members
	}
}